package com.syedu.day07.v2;

import cn.hutool.core.util.ArrayUtil;

/**
 * description：业务类
 * @author Administrator
 * @date 2022/3/16 16:07
 */
public class EmployeeService {
    /**
     * 添加下属的方法
     */
    public void addEmp(Employee manager, Employee newEmployee) {
        //判断是否是上司
        if (manager.getEmployees() != null) {
            manager.setEmployees(ArrayUtil.append(manager.getEmployees(), newEmployee));
        } else {
            System.err.println("该员工无权添加下属...");
        }
    }

    /**
     * 输出自己所属下属的方法
     */
    public void showEmps(Employee manager) {
        if (manager.getEmployees() != null && manager.getEmployees().length > 0) {
            for(Employee e : manager.getEmployees()){
                System.out.println(e.getName() + "," + e.getSalary());
            }
        }else{
            System.err.println("该员工暂无下属信息...");
        }
    }

    /**
     * 获取自己下属的人数个数
     */
    public int getEmpCount(Employee manager) {
        int count = 0;
        if (manager.getEmployees() != null){
            count = manager.getEmployees().length;
        }
        return count;
    }
}